package io.renren.modules.substation.service.impl;

import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import io.renren.modules.substation.dao.TInfoEfencePointDao;
import io.renren.modules.substation.entity.TInfoEfencePointEntity;
import io.renren.modules.substation.service.TInfoEfencePointService;


@Service("tInfoEfencePointService")
public class TInfoEfencePointServiceImpl extends ServiceImpl<TInfoEfencePointDao, TInfoEfencePointEntity> implements TInfoEfencePointService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<TInfoEfencePointEntity> page = this.page(
                new Query<TInfoEfencePointEntity>().getPage(params),
                new QueryWrapper<TInfoEfencePointEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public List<TInfoEfencePointEntity> getByDevCode(String devCode){
        return baseMapper.getByDevCode(devCode);
    }

    @Override
    public TInfoEfencePointEntity getByPostCodeAndDevCode(TInfoEfencePointEntity tInfoEfencePointEntity){
        return baseMapper.getByPostCodeAndDevCode(tInfoEfencePointEntity);
    }


    @Override
    public int updateByPostCodeAndDevCode(TInfoEfencePointEntity tInfoEfencePointEntity){
        return baseMapper.updateByPostCodeAndDevCode(tInfoEfencePointEntity);
    }

    @Override
    public boolean removeBydevCode(String devCode){
        return baseMapper.removeBydevCode(devCode);
    }

    @Override
    public int updatePnByPostCode(String devId,String addr,String status){
        TInfoEfencePointEntity tInfoEfencePointEntity = new TInfoEfencePointEntity();
        tInfoEfencePointEntity.setDevCode(devId);
        tInfoEfencePointEntity.setPostAddr(addr);
        tInfoEfencePointEntity.setPostNa(status);
        tInfoEfencePointEntity.setLastOpr((long)0);
        tInfoEfencePointEntity.setLastTime(new Date());
        return baseMapper.updatePnByPostCode(tInfoEfencePointEntity);
    }

}